package resp

type Response struct {
	Status    bool        `json:"status"`
	Massage   string      `json:"msg"`
	Code      int         `json:"code"`
	Data      interface{} `json:"data,omitempty"`
	Token     string      `json:"token,omitempty"`
	Params    interface{} `json:"params,omitempty"`
}

type PageResponse struct {
	Response
	PageSize  int         `json:"page_size"`
	PageNum   int         `json:"page_num"`
	PageCount int         `json:"page_count"`
	ItemCount int         `json:"item_count"`
}

// 默认返回信息
const (
	MsgSuccess            = "操作成功"
	MsgBindDataFailed     = "绑定参数失败"
	MsgMissingParameter   = "缺少参数"
	MsgInternalCallFailed = "内部错误"
)

func MakeSuccessResponse(msg ...string) Response {
	return Response{
		Status:  true,
		Massage: append(msg, MsgSuccess)[0],
	}
}

func MakeSuccessDataResponse(data interface{}) Response {
	return Response{
		Status:  true,
		Massage: MsgSuccess,
		Data:    data,
	}
}

func MakeSuccessDataPageResponse(data interface{}, page PageFields) PageResponse {
	return PageResponse{
		Response:Response{
			Status:    true,
			Massage:   MsgSuccess,
			Data:      data,
		},
		PageSize:  page.Size(),
		PageNum:   page.Num(),
		PageCount: page.PageCount,
		ItemCount: page.ItemCount,
	}
}

func MakeErrorResponse(err error) Response {
	return Response{
		Status:  false,
		Massage: err.Error(),
	}
}

func MakeInternalErrorResponse() Response {
	return Response{
		Status:  false,
		Massage: MsgInternalCallFailed,
	}
}